<?php
/*  File: MenuXML.inc.php
	
	Notes:
	1st version is for menu.xml used by Cost Biter
	
	Change History:
	09/12/2009 [1.00] Initial Version
*/
class MenuXML {

    private $CompleteDOMFile;
    private $TopLevels;
    private $TopLevelTags;

    public function __construct($file) {
        $MenuDOM			= new DOMDocument();
        //$MenuDOM                        = new DOMDocument('1.0', 'utf-8');
        $MenuDOM->preserveWhiteSpace	= false;
        $MenuDOM->load($file);
        $MenuDOM->formatOutput		= true;
        $this->TopLevels		= "Category";
        $this->CompleteDOMFile		= $MenuDOM;
        $this->TopLevelTags		= $MenuDOM->getElementsByTagName($this->TopLevels);
    }

    public function ClearFilters() {
        unset($_SESSION['ActiveFilters']);
    }

    public function RemoveActiveFilter() {
        /* args: $_SESSION['ActiveFilters'],"key","etc" */
//		$args  = func_get_args();
//		$_SESSION['ActiveFilters'] = array_diff_key($args[0],array_flip(array_slice($args,1)));
    }

    public function AddActiveFilter($array) {
//		if(count($_SESSION['ActiveFilters']) != 0 ) { $_SESSION['ActiveFilters'] = array_merge($_SESSION['ActiveFilters'], $array);
//		} else { $_SESSION['ActiveFilters'] = $array; }
    }

    public function GetMenu($Category,$MenuName,$SubMenuName) {
        //	if(isset($_SESSION['ActiveFilters'])) {
        for ($x = 0; $x < $this->TopLevelTags->length; $x++) {
            if (strtolower($this->TopLevelTags->item($x)->getAttribute("Name")) == strtolower($Category)) {
                $proditems = $this->TopLevelTags->item($x)->getElementsByTagName($MenuName);
                $proditems_length = $proditems->length;
                $x = $this->TopLevelTags->length;

                for ($y = 0; $y < $proditems->length; $y++) {
                    $proditem = $proditems->item($y)->getElementsByTagName($SubMenuName);
                    $proditem_length = $proditem->length;
                    $y = $proditems->length;
                    for ($z = 0; $z < $proditem->length; $z++) {
                        $Menu[]	= array(
                                'Count'=>$proditem->item($z)->getAttribute("Count"),
                                'Name'=>$proditem->item($z)->nodeValue
                        );
                    }
                }
            }
        }
        //	} else {
        // Gather information from Products.xml
        //	}
        return $Menu;
    }
}
?>